package com.niit.wallswapers;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

public class WallSwapActivity extends Activity{
    private Button mSetButton;
    private Button mUnsetButton;
    private RadioButton mOneMinRadio;
    private RadioButton mFiveMinRadio;
    private RadioButton mTenMinRadio;
    private RadioButton mThirtyMinRadio;
    private RadioButton mOneHourRadio;
    private RadioGroup mTimeRadioGroup;
    public int mChangeTime = 60 ;

    @SuppressLint({"MissingInflatedId", "WrongViewCast"})
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mSetButton = (Button) findViewById(R.id.button1);
        mUnsetButton = (Button) findViewById(R.id.button2);
        mOneMinRadio = (RadioButton) findViewById(R.id.radio0);
        mFiveMinRadio = (RadioButton) findViewById(R.id.radio1);
        mTenMinRadio = (RadioButton) findViewById(R.id.radio2);
        mThirtyMinRadio = (RadioButton) findViewById(R.id.radio3);
        mOneHourRadio = (RadioButton) findViewById(R.id.radio4);
        mTimeRadioGroup = (RadioGroup) findViewById(R.id.radioGroup1);
        mUnsetButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent mDisableIntent = new Intent(WallSwapActivity.this, WallpaperChangeService.class);
                stopService(mDisableIntent);
                finish();
            }
        });
        mSetButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                int mRadioID = mTimeRadioGroup.getCheckedRadioButtonId();
                if (mOneMinRadio.getId() == mRadioID) {
                    mChangeTime = 60;
                } else if (mFiveMinRadio.getId() == mRadioID) {
                    mChangeTime = 300;
                } else if (mTenMinRadio.getId() == mRadioID) {
                    mChangeTime = 600;
                } else if (mThirtyMinRadio.getId() == mRadioID) {
                    mChangeTime = 1800;
                } else if (mOneHourRadio.getId() == mRadioID) {
                    mChangeTime = 3600;
                }
                Intent mServiceIntent = new Intent(WallSwapActivity.this, WallpaperChangeService.class);
                Bundle mBundleTime = new Bundle();
                mBundleTime.putInt("time", mChangeTime);
                mServiceIntent.putExtras(mBundleTime);
                startService(mServiceIntent);
                finish();
            }
        });
    }
}
